﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace IDAL
{
    /// <summary>
    /// 数据层父接口
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IBaseDAL<T> where T : class,new()
    {
        //EF上下文
        //MODEL.QGZXEntities db = new MODEL.QGZXEntities();

        //增删改查
        #region 新增实体 +int Add(T model)
        /// <summary>
        /// 新增实体
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        int Add(T model); 
        #endregion

        #region 根据id删除 + Del(T model)
        /// <summary>
        /// 根据id删除
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        int Del(T model); 
        #endregion

        #region 根据条件删除 +DelBy(Expression<Func<T, bool>> delWhere)
        /// <summary>
        /// 根据条件删除
        /// </summary>
        /// <param name="delWhere"></param>
        /// <returns></returns>
        int DelBy(Expression<Func<T, bool>> delWhere); 
        #endregion

        #region 修改 + Modify(T model, params string[] proNames)
        /// <summary>
        ///修改
        /// </summary>
        /// <param name="model">要修改的实体对象</param>
        /// <param name="proNames">要修改的属性名称</param>
        /// <returns></returns>
        int Modify(T model, params string[] proNames); 
        #endregion

        #region 批量修改 + ModifyBy(T model, Expression<Func<T, bool>> whereLambda, params string[] modifiedProNames)
        /// <summary>
        /// 批量修改
        /// </summary>
        /// <param name="model">要修改的实体对象</param>
        /// <param name="whereLambda">查询条件</param>
        /// <param name="modifiedProNames">要修改的属性名称</param>
        /// <returns></returns>
        int ModifyBy(T model, Expression<Func<T, bool>> whereLambda, params string[] modifiedProNames); 
        #endregion

        #region 根据条件查询 + List<T> GetListBy(Expression<Func<T, bool>> whereLambda)
        /// <summary>
        /// 根据条件查询
        /// </summary>
        /// <param name="whereLambda"></param>
        /// <returns></returns>
        List<T> GetListBy(Expression<Func<T, bool>> whereLambda); 
        #endregion

        #region 根据条件排序和查询 + List<T> GetListBy<TKey>
        /// <summary>
        /// 根据条件排序和查询
        /// </summary>
        /// <typeparam name="TKey">排序字段类型</typeparam>
        /// <param name="whereLambda">查询条件lambda表达式</param>
        /// <param name="orderLambda">排序条件lambda表达式</param>
        /// <returns></returns>
        List<T> GetListBy<TKey>(Expression<Func<T, bool>> whereLambda, Expression<Func<T, TKey>> orderLambda); 
        #endregion

        #region 分页查询 + List<T> GetPagedList<Tkey>
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <typeparam name="Tkey"></typeparam>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页容量</param>
        /// <param name="whereLambda">条件 Lambda表达式</param>
        /// <param name="orderBy">排序 Lambda表达式</param>
        /// <returns></returns>
        List<T> GetPagedList<Tkey>(int pageIndex, int pageSize, Expression<Func<T, bool>> whereLambda, Expression<Func<T, Tkey>> orderBy); 
        #endregion
    }
}
